﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace YXShop.TemplateAction
{
    public partial class LabelParse
    {
        public string ArticleContent()
        {
            string mystyle = this.Label_Inserted;
            string strcontent = "";
            YXShop.BLL.SystemInfo.ArticleChannel articleBll = new YXShop.BLL.SystemInfo.ArticleChannel();
            int memberId = 0;


            if (!string.IsNullOrEmpty(mystyle))
            {
                strcontent = mystyle;
                string newid = ChangeHope.WebPage.PageRequest.GetQueryString("Id");  //文章ID
                if (ChangeHope.Common.ValidateHelper.IsNumber(newid))
                {
                    YXShop.BLL.SystemInfo.Article bll = new YXShop.BLL.SystemInfo.Article();
                    
                    YXShop.Model.SystemInfo.Article model = bll.GetModel(Convert.ToInt32(newid));
                    if (model != null)
                    {
                        if (HttpContext.Current.Session["MemberID"] != null)
                        {
                            memberId = Convert.ToInt32(HttpContext.Current.Session["MemberID"]);
                            if (ChangeHope.Common.ValidateHelper.IsNumber(model.Channel))
                            {
                                YXShop.BLL.Member.MemberAccount accountBll = new YXShop.BLL.Member.MemberAccount();
                                YXShop.Model.Member.MemberAccount account = accountBll.GetModel(memberId);
                                YXShop.Model.SystemInfo.ArticleChannel article = articleBll.GetModel(model.Channel);
                                if (article != null)
                                {
                                    string role = article.Power.ToString();
                                    if (role != "")
                                    {
                                        string[] list = role.Split(',');
                                        string ss = list[0];
                                        int count = -1;
                                        for (int i = 0; i < list.Length; i++)
                                        {
                                            if (list[i].ToString() == account.UserGroup.ToString())
                                            {
                                                count = 1;
                                            }
                                        }
                                        if (count <= 0)
                                        {
                                            return "您的访问权限受限制";
                                        }
                                    }
                                }
                            }
                        }

                        bll.Amend(model.Id, "BrowseCount", model.BrowseCount + 1);
                        if (strcontent.IndexOf("[#Articles_Title]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_Title]", model.Title.ToString());
                        }
                        if (strcontent.IndexOf("[#Articles_SubTitle]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_SubTitle]", model.SubTitle.ToString());
                        }
                        if (strcontent.IndexOf("[#Articles_Author]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_Author]", model.Author.ToString());
                        }
                        if (strcontent.IndexOf("[#Articles_SouesURL]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_SouesURL]", model.LinkUrl.ToString());
                        }
                        if (strcontent.IndexOf("[#Articles_Synopsis]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_Synopsis]", model.Introduction.ToString());
                        }
                        if (strcontent.IndexOf("[#Articles_Content]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_Content]", model.Content.ToString());
                        }
                        if (strcontent.IndexOf("[#Articles_UpdateTime]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_UpdateTime]", model.UpdateTime.ToString());
                        }
                        if (strcontent.IndexOf("[#Articles_CreateTime]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_CreateTime]", model.CreateTime.ToString());
                        }
                        if (strcontent.IndexOf("[#Articles_Source]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_Source]", model.CopyFrom.ToString());
                        }
                        if (strcontent.IndexOf("[#Articles_OnClick]") > -1)
                        {
                            strcontent = strcontent.Replace("[#Articles_OnClick]",model.BrowseCount.ToString());
                        }

                    }
                    else
                    {
                        strcontent = "";
                    }
                }
                else
                {
                    strcontent = "";
                }

            }
          
            return strcontent.ToString();
        }
    }
}
